﻿using Ledict.ConditionExtract.Model;
using Ledict.Core.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ledict.ConditionExtract.DAL
{
    public class PresentationResultsDAL
    {
        private string DbName;
        public PresentationResultsDAL()
        {
            DbName = "JudgeProcess";
        }

        /// <summary>
        /// 添加结果集
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public bool AddPresentation(PresentationResults Model)
        {
            try
            {
                string sql=$"insert into PresentationResults (CauseId, Flag, Presentation, PresentationRelation) values ('{Model.CauseId}',{Model.Flag},'{Model.Presentation}','{Model.PresentationRelation}')";
                //2017-07-04 ljj 为了将SYS_Express_Word_Process表移除System库做出的修改
                Database oBase = DatabaseFactory.CreateDatabase(DbName);
                DbCommand oCmd = oBase.GetSqlStringCommand(sql);
                if (oBase.ExecuteNonQuery(oCmd) > 0)
                {
                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 获取结果集数据
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public DataTable GetPresentationData(string CC_IDList, string causeId)
        {
            string strSql =$" select * from PresentationResults where PresentationRelation<> '{CC_IDList}' and CauseId='{causeId}' ";
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql);
            DataTable OtB = oBase.ExecuteDataSet(oCmd).Tables[0];
            if (OtB.Rows.Count > 0)
            {
                return OtB;
            }
            else
            {
                return new DataTable();
            }
        }

        /// <summary>
        /// 获取是否存在结果集数据
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public bool IsExsitsPresentationData(PresentationResults Model)
        {
            string strSql = $" select * from PresentationResults where  CauseId='{Model.CauseId}' and Flag={Model.Flag} and  Presentation='{Model.Presentation}' and PresentationRelation='{Model.PresentationRelation}' ";
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql);
            DataTable OtB = oBase.ExecuteDataSet(oCmd).Tables[0];
            if (OtB.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
